package com.fitbet.admin.entity.search.bonus;

import java.util.Date;
import java.util.Map;

import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

/**
 * @author xiaoHU
 *
 */
public class UserWithdrawalSearch implements QueryBuilder {

    /** 用户 */
    private Long userId;

    /**
     * 支付开始时间
     * 
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date payBeginTime;
    
    /**
     * 支付结束时间
     * 
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date payEndTime;
    
    /**
     * 创建开始时间
     * 
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginCreateTime;
    
    /**
     * 创建结束时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endCreateTime;

    private QueryFilter queryFilter;

    private QueryOrder queryOrder;

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {
        if (queryFilter == null || refresh) {

            queryFilter = new QueryFilter();

            queryFilter.addDateTimeBetween("payTime", payBeginTime, payEndTime)
                       .addDateTimeBetween("createTime", beginCreateTime, endCreateTime)
                       .addEquals("user.id", userId);
        }

        return queryFilter;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        if (queryOrder == null) {
            queryOrder = new QueryOrder();
        }
        return queryOrder;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        return "FROM UserWithdrawal " + getPreparedFilter(false).whereSentence();
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }

    /**
     * @return the userId
     */
    public Long getUserId() {
        return userId;
    }

    /**
     * @return the payBeginTime
     */
    public Date getPayBeginTime() {
        return payBeginTime;
    }

    /**
     * @return the payEndTime
     */
    public Date getPayEndTime() {
        return payEndTime;
    }

    /**
     * @return the beginCreateTime
     */
    public Date getBeginCreateTime() {
        return beginCreateTime;
    }

    /**
     * @return the endCreateTime
     */
    public Date getEndCreateTime() {
        return endCreateTime;
    }

    /**
     * @param userId the userId to set
     */
    public void setUserId(Long userId) {
        this.userId = userId;
    }

    /**
     * @param payBeginTime the payBeginTime to set
     */
    public void setPayBeginTime(Date payBeginTime) {
        this.payBeginTime = payBeginTime;
    }

    /**
     * @param payEndTime the payEndTime to set
     */
    public void setPayEndTime(Date payEndTime) {
        this.payEndTime = payEndTime;
    }

    /**
     * @param beginCreateTime the beginCreateTime to set
     */
    public void setBeginCreateTime(Date beginCreateTime) {
        this.beginCreateTime = beginCreateTime;
    }

    /**
     * @param endCreateTime the endCreateTime to set
     */
    public void setEndCreateTime(Date endCreateTime) {
        this.endCreateTime = endCreateTime;
    }

    /**
     * @param queryFilter the queryFilter to set
     */
    public void setQueryFilter(QueryFilter queryFilter) {
        this.queryFilter = queryFilter;
    }

    /**
     * @param queryOrder the queryOrder to set
     */
    public void setQueryOrder(QueryOrder queryOrder) {
        this.queryOrder = queryOrder;
    }

}
